Check repo permission prior to attempting to modify it
authorMatthew Barnes <mbarnes@redhat.com>
Fri, 16 Jan 2015 18:28:36 +0000 (13:28 -0500)
committerColin Walters <walters@verbum.org>
Wed, 25 Mar 2015 21:24:05 +0000 (17:24 -0400)
Fail early with a helpful message if the user does not have sufficient
permission to modify an OSTree repository.

src/ostree/ot-builtin-commit.c
src/ostree/ot-builtin-prune.c
src/ostree/ot-builtin-pull-local.c
src/ostree/ot-builtin-pull.c
src/ostree/ot-builtin-reset.c
src/ostree/ot-builtin-static-delta.c
src/ostree/ot-builtin-summary.c

index cd9e9a9fba7add542865c2c840db938b6e107afa..db17f5387f6c1a7e362df44f5b9ba641c1cd4fd8 100644 (file)
@@ -313,6 +313,9 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (opt_statoverride_file)
     {
       if (!parse_statoverride_file (&mode_adds, cancellable, error))
index cd05b2f39a0a4feab61989b1e535fd15522269a6..89ad2e5d4e89b4da44851372017c228a8e0b771d 100644 (file)
@@ -55,6 +55,9 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!opt_no_prune && !ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (opt_refs_only)
     pruneflags |= OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
   if (opt_no_prune)
index 4588ccb05b9b6be9a2f70c43416e4d0070b744d8..2b7bf67cec0fd0b84ce9a813d53a4f2137a8203f 100644 (file)
@@ -58,6 +58,9 @@ ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GEr
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 2)
     {
       gchar *help = g_option_context_get_help (context, TRUE, NULL);
index 0846605464a0ea3372cbd5bab2cddc3b6106511d..91db17d1d4eb1f1b64190cdafb6600e75c479e9d 100644 (file)
@@ -57,6 +57,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 2)
     {
       ot_util_usage_error (context, "REMOTE must be specified", error);
index 0a72846dc7ec8c0cb0cbdf0aab68c847bf95e8c3..a09e9a4fb2f687ec892a1c013db0395893f25a5c 100644 (file)
@@ -100,6 +100,9 @@ ostree_builtin_reset (int           argc,
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc <= 2)
     {
       ot_util_usage_error (context, "A ref and commit argument is required", error);
index eba852fc6b334b925ea695791c3628d4571219ff..9eece842bfcea3f50b4dac8b3c9124c8b1f21120 100644 (file)
@@ -140,6 +140,9 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab
   if (!ostree_option_context_parse (context, generate_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc >= 3 && opt_to_rev == NULL)
     opt_to_rev = argv[2];
 
@@ -248,6 +251,9 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc
   if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
index d7bed4420f785689dc153d2a46236e109ab20c57..81566898bbb7013f9b4fc99d5fdcfe1d32979469 100644 (file)
@@ -46,6 +46,9 @@ ostree_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError
 
   if (opt_update)
     {
+      if (!ostree_ensure_repo_writable (repo, error))
+        goto out;
+
       if (!ostree_repo_regenerate_summary (repo, NULL, cancellable, error))
         goto out;
     }